﻿using chatGUI.Model;
using chatGUI.SingeltonData;
using FreeSql.DataAnnotations;

namespace chatGUI.DataBase.Entity;

[Table(Name = "groups")]
public class Group{
    [Column(Name = "gid",IsPrimary = true)]
    public string Gid{ get; set; }
    [Column(Name = "gname")]
    public string Gname{ get; set; }
    [Column(Name = "gdate")]
    public string Gdate{ get; set; }

    public Group()
    {

    }
    public Group(messageData.Group group)
    {
        Gid = group.gid;
        Gname = group.gname;
        Gdate = group.gdate.ToString();
    }
    public static explicit operator Model.friendListModel(Group group)
    {
        return new Model.friendListModel
        {
            Id = group.Gid,
            IsGroup = true,
            FriendNickName = group.Gname,
            AvatarUrl = miniClientData.Instance.client.file_helper.path + @"\image\groups_icon.png"
        };
    }

    public static explicit operator userDataModel(Entity.Group group)
    {
        if(group == null)
        {
            return new userDataModel
            {
                Uid = "error",
                AvatarUrl = miniClientData.Instance.client.file_helper.path + @"\image\groups_icon.png",
                NickName = "error",
                RemarkName = "error"
            };
        }
        return new userDataModel
        {
            Uid = group.Gid,
            AvatarUrl = miniClientData.Instance.client.file_helper.path + @"\image\groups_icon.png",
            NickName = group.Gname,
            RemarkName = group.Gname
        };
    }
    public override string ToString(){
        return $"{nameof(Gid)}: {Gid}, {nameof(Gname)}: {Gname}, {nameof(Gdate)}: {Gdate}";
    }
}